<template>
  <div class="adduser">
    <h3>添加帐号</h3>
    <div class="adduser-input">
      <p>
        <span>帐号</span>
        <el-input
          prefix-icon="el-icon-user"
          placeholder="请输入用户名"
          v-model="username"
          clearable
          style="width: 200px"
        >
        </el-input>
      </p>
      <p>
        <span> 密码</span>
        <el-input
          prefix-icon="el-icon-lock"
          placeholder="请输入密码"
          v-model="password"
          show-password
          style="width: 200px"
        ></el-input>
      </p>
      <p>
        <span>用户组</span>
        <el-select
          v-model="selectgo"
          placeholder="请选择用户组"
          style="width: 200px"
        >
          <el-option
            v-for="(item, i) in options"
            :key="i"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </p>
      <p class="adduser-button">
        <span></span>
        <button class="adduser-add" @click="clickadd">添加</button>
        <button>重置</button>
      </p>
    </div>
  </div>
</template>

<script>
// 引入添加帐号axios
// @/ 表示直接找到src根目录
import { adduser } from "@/apis/user";
export default {
  data() {
    return {
      // manageshow: false,
      username: "",
      password: "",
      selectgo: "普通管理员",
      options: [
        {
          value: "普通管理员",
          label: "普通管理员",
        },
        {
          value: "超级管理员",
          label: "超级管理员",
        },
      ],
    };
  },
  methods: {
    clickadd() {
      // this.manageshow = this.manageshow == false ? true : false;
      adduser({
        account: this.username,
        password: this.password,
        userGroup: this.selectgo,
      }).then((res) => {
        // console.log(res);
        if (res.data.code == 0) {
          this.$message({
            showClose: true,
            message: "恭喜您，帐号添加成功",
            type: "success",
          });
          // 清空列表
          this.username = "";
          this.password = "";
        } else {
          this.$message({
            showClose: true,
            message: "警告哦，帐号添加失败",
            type: "warning",
          });
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.adduser {
  margin: 20px;
  background-color: #fff;
  box-sizing: border-box;
  padding: 0 20px 20px 20px;
  position: relative;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  h3 {
    line-height: 60px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 20px;
  }
  .adduser-input {
    width: 300px;
    display: flex;
    flex-direction: column;
    p {
      margin-bottom: 20px;
      span {
        width: 80px;
        display: inline-block;
        margin-right: 20px;
        text-align: right;
      }
    }
    .adduser-button {
      width: 300px;
      button {
        width: 60px;
        border: 0;
        border-radius: 5px;
        margin-right: 10px;
        line-height: 40px;
      }
      button:last-child {
        background-color: #fff;
        border: 1px solid #ccc;
      }
      .adduser-add {
        background-color: #409eff;
        color: #fff;
      }
    }
  }
}
</style>